﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SedCup.Code.Model;

namespace SedCup.Code.View.Components
{
    public partial class PanelWorkersList : UserControl
    {
        private List<Agent> agents;
        /// <summary>
        /// Dolgozók ezen a mezőn
        /// </summary>
        public List<Agent> Agents
        {
            get { return agents; }
            set { agents = value; this.UpdatePanel(); }
        }

        private PanelWorker panelWorker = new PanelWorker();

        /// <summary>
        /// 
        /// </summary>
        public PanelWorkersList()
        {
            InitializeComponent();

            this.BackColor = Settings.GUI_BACKCOLOR_FIELD;
            this.flowLayoutPanel.BackColor = Settings.GUI_BACKCOLOR_FIELD;

            this.panelWorker.Dock = DockStyle.Fill;
            this.Controls.Add(this.panelWorker);
        }

        /// <summary>
        /// Panel frissítése
        /// </summary>
        public void UpdatePanel()
        {
            if (this.Agents == null || this.Agents.Count == 0) {
                this.panelWorker.Visible = false;
                this.flowLayoutPanel.Visible = false;
            } else if (this.Agents.Count == 1) {
                this.panelWorker.WorkerName = this.Agents[0].agentId;

                if (this.Agents[0].type == "junior") {
                    this.panelWorker.WorkerRank = PanelWorker.Rank.JUNIOR;
                } else if (this.Agents[0].type == "senior") {
                    this.panelWorker.WorkerRank = PanelWorker.Rank.SENIOR;
                } else {
                    this.panelWorker.WorkerRank = PanelWorker.Rank.GURU;
                }

                this.panelWorker.LocalTeam = (this.Agents[0].owner == "me");

                // TODO: pontok, elvégzett feladatok

                this.panelWorker.Visible = true;
                this.flowLayoutPanel.Visible = false;
            } else {
                this.flowLayoutPanel.Controls.Clear();

                foreach (var item in this.Agents)
                {
                    PanelWorkerMini worker = new PanelWorkerMini();

                    worker.WorkerName = item.agentId;

                    if (item.type == "junior")
                    {
                        worker.WorkerRank = PanelWorker.Rank.JUNIOR;
                    }
                    else if (item.type == "senior")
                    {
                        worker.WorkerRank = PanelWorker.Rank.SENIOR;
                    }
                    else
                    {
                        worker.WorkerRank = PanelWorker.Rank.GURU;
                    }

                    worker.LocalTeam = (item.owner == "me");

                    // TODO: pontok, elvégzett feladatok

                    this.flowLayoutPanel.Controls.Add(worker);
                }

                this.panelWorker.Visible = false;
                this.flowLayoutPanel.Visible = true;
            }
        }
    }
}
